#include <stdio.h> /* for NULL */
#include "Interface.h"

PN31_KEYCODE	g_PN31Keyboard[] = {
	{ K_POWER,			"K_POWER",		{0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }},
	{ K_MEDIAPLAYER,	"K_MEDIAPLAYER",{0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 }},
	{ K_IEXPLORE,		"K_IEXPLORE",	{0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 }},
	{ K_EMAIL,			"K_EMAIL",		{0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 }},
	{ K_EXPLORER,		"K_EXPLORER",	{0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }},
	{ K_FAVORITE,		"K_FAVORITE",	{0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 }},
	{ K_PREVIOUS,		"K_PREVIOUS",	{0x03, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }},
	{ K_NEXT,			"K_NEXT",		{0x03, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00 }},
	  
	{ K_REWIND,			"K_REWIND",		{0x03, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }},
	{ K_PLAYPAUSE,		"K_PLAYPAUSE",	{0x03, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }},
	{ K_FORWARD,		"K_FORWARD",	{0x03, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }},
	{ K_MAXWIN,			"K_MAXWIN",		{0x01, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00 }},
	{ K_STOP,			"K_STOP",		{0x01, 0x01, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00 }},
	{ K_MUTE,			"K_MUTE",		{0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }},
	  
	{ K_VOLUP,			"K_VOLUP",		{0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }},
	{ K_VOLDOWN,		"K_VOLDOWN",	{0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }},
	{ K_WINDOWS,		"K_WINDOWS",	{0x01, 0x00, 0x00, 0xe3, 0x00, 0x00, 0x00, 0x00 }},
	{ K_PGUP,			"K_PGUP",		{0x01, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x00 }},
	{ K_PGDOWN,			"K_PGDOWN",		{0x01, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x00 }},
	  
	{ K_ESC,			"K_ESC",		{0x01, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00 }},
	{ K_TAB,			"K_TAB",		{0x01, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00 }},
	{ K_DEL,			"K_DEL",		{0x01, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00 }},
	{ K_1,				"K_1",			{0x01, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00 }},
	{ K_2,				"K_2",			{0x01, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00 }},
	{ K_3,				"K_3",			{0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00 }},
	{ K_4,				"K_4",			{0x01, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00 }},
	{ K_5,				"K_5",			{0x01, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00 }},
	{ K_6,				"K_6",			{0x01, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00 }},
	{ K_7,				"K_7",			{0x01, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00 }},
	{ K_8,				"K_8",			{0x01, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00 }},
	{ K_9,				"K_9",			{0x01, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00 }},
	{ K_0,				"K_0",			{0x01, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x00 }},
	{ K_DOT,			"K_DOT",		{0x01, 0x00, 0x00, 0x37, 0x00, 0x00, 0x00, 0x00 }},
	{ K_RETURN,			"K_RETURN",		{0x01, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00 }}
};


PN31_KEYCODE* FindPN31Key (BYTE* pBuff)
{
	PN31_KEYCODE*	pResult = NULL;
	int				i;

	for (i=0; i<sizeof(g_PN31Keyboard)/sizeof(PN31_KEYCODE); i++)
	{
		if (memcmp (g_PN31Keyboard[i].Code, pBuff, sizeof(g_PN31Keyboard[i].Code)) == 0)
		{
			pResult = &g_PN31Keyboard[i];
			break;
		}
	}
	return pResult;
}
